/**
 * [一句话描述该类的功能]
 *
 * @author : [kai]
 * @version : [v1.0]
 * @createTime : [2022/10/25 13:55]
 */


package com.find.service.lmpl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.find.dao.ItemDao;
import com.find.domain.Item;
import com.find.domain.User;
import com.find.service.ItemService;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class ItemServiceImpl extends ServiceImpl<ItemDao,Item> implements ItemService{
    //TODO
    @Autowired
    private ItemDao itemDao;

    @Override
    public boolean saveItem(Item item) {
        Date date = new Date();
        item.setTime(date);
        return itemDao.insert(item) > 0;
    }

    @Override
    public boolean delById(Integer id) {
        return itemDao.deleteById(id) > 0;
    }

    @Override
    public boolean updateItem(Item item) {
        return itemDao.updateById(item) > 0;
    }

    @Override
    public IPage<Item> getPage(int currentPage, int PageSize) {
        IPage page = new Page(currentPage, PageSize);
        itemDao.selectPage(page, null);
        return page;
    }

    @Override
    public IPage<Item> getPage(int currentPage, int PageSize, Item item) {
        LambdaQueryWrapper<Item> lqw = new LambdaQueryWrapper<Item>();
        lqw.like(Strings.isNotEmpty(item.getName()), Item::getName, item.getName());
        IPage page = new Page(currentPage, PageSize);
        itemDao.selectPage(page, lqw);
        return page;
    }

    @Override
    public List<Item> notClaimed(){
        QueryWrapper<Item> qw= new QueryWrapper<Item>();
        qw.eq("item_claim",0);
        return itemDao.selectList(qw);
    }

}
